package com.middlegroup.common.enums;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;

/**
 *
 * @author pc
 * @date 2019/1/25
 */
public enum ServiceType {

    OUT("OUT","出款"),
    IN("IN","收款"),


    DF("DF", "代付"),
    DEDUCT("DEDUCT", "代收"),


    DFQUERY("DFQUERY","代付查询"),
    DSQUERY("DSQUERY","代收查询"),
    BINDCARDQUERY("BINDCARDQUERY","绑卡查询"),


    BINDCARDAPPLY("BINDCARDAPPLY","协议绑卡申请"),
    BINDCARDCONFIRM("BINDCARDCONFIRM","协议绑卡确认"),
    RESENDSMS("RESENDSMS","协议绑卡重发短信验证码"),


    PROTOCOL_PAY("PROTOCOL_PAY", "协议支付"),
    PROTOCOL_FIRSTDEDUCTAPPLY("PROTOCOL_FIRSTDEDUCTAPPLY", "协议支付首次支付申请"),
    PROTOCOL_FIRSTDEDUCTCONFIRM("PROTOCOL_FIRSTDEDUCTCONFIRM", "协议支付首次支付确认"),
    PROTOCOL_FIRSTDEDUCTRESENDSMS("PROTOCOL_FIRSTDEDUCTRESENDSMS", "协议支付首次支付重发短信验证码"),
    PROTOCOL_SECONDDEDUCT("PROTOCOL_SECONDDEDUCT", "协议支付二次支付"),


    QUICK_PAY("QUICK_PAY","快捷支付"),
    QUICKPAY_FIRSTDEDUCTAPPLY("QUICKPAY_FIRSTDEDUCTAPPLY", "快捷支付首次支付申请"),
    QUICKPAY_FIRSTDEDUCTCONFIRM("QUICKPAY_FIRSTDEDUCTCONFIRM", "快捷支付首次支付确认"),
    QUICKPAY_FIRSTDEDUCTRESENDSMS("QUICKPAY_FIRSTDEDUCTRESENDSMS", "快捷支付首次支付重发短信验证码"),

    wx_h5("wx_h5", "微信H5支付"),
    wx_sdk("wx_sdk", "微信SDK支付"),
    alipay_h5("alipay_h5", "阿里H5支付"),
    alipay_sdk("alipay_sdk", "阿里SDK支付"),
    paypal("paypal", "paypal支付")
    ;

    private String code;
    private String name;

    /**
     * @param code
     * @param name
     */
    ServiceType(String code, String name) {
        this.code = code;
        this.name = name;
    }

    /**
     * 根据code获取name
     * @param code
     * @return
     */
    public static String getName(String code) {
        for (ServiceType e : ServiceType.values()) {
            if (StringUtils.equals(e.getCode(),code)) {
                return e.name;
            }
        }
        return null;
    }

    /**
     *将该枚举全部转化成json
     * @return
     */
    public static String toJson(){
        JSONArray jsonArray = new JSONArray();
        for (ServiceType e : ServiceType.values()) {
            JSONObject object = new JSONObject();
            object.put("code", e.getCode());
            object.put("name", e.getName());
            jsonArray.add(object);
        }
        return jsonArray.toString();
    }

    /**
     * 重写toString，单个转化成json
     * @return
     */
    @Override
    public String toString() {
        JSONObject object = new JSONObject();
        object.put("code",code);
        object.put("name",name);
        return object.toString();
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
